package com.qyl.deguru.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.qyl.deguru.common.PageModel;
import com.qyl.deguru.common.QueryVo;
import com.qyl.deguru.dao.BaseDao;
import com.qyl.deguru.dao.ShopDao;
import com.qyl.deguru.dto.Shop;
import com.qyl.deguru.dto.ShopType;
import com.qyl.deguru.mapper.CommentMapper;
import com.qyl.deguru.mapper.OrderItemMapper;
import com.qyl.deguru.mapper.ShopMapper;
import com.qyl.deguru.mapper.TimeLimitedMapper;

public class ShopDaoImple extends BaseDao implements ShopDao{
	@Override
	public List<Shop> showShopList(Shop shop,PageModel pagemodel) {
		SqlSession session=getSqlSession();
		ShopMapper shopMapper=session.getMapper(ShopMapper.class);
		List<Shop> shops=shopMapper.showShopList(shop,pagemodel);
		closeSqlSession();
		return shops;
	}
	@Override
	public int getcount() {
		SqlSession session=getSqlSession();
		ShopMapper shopMapper=session.getMapper(ShopMapper.class);
		int count=shopMapper.getcount();
		closeSqlSession();
		return count;
	}
	@Override
	public int delShopById(int id) {
		SqlSession session=getSqlSession();
		CommentMapper commentMapper=session.getMapper(CommentMapper.class);
		commentMapper.delCommentByGoods_id(id);
		OrderItemMapper orderItemMapper=session.getMapper(OrderItemMapper.class);
		orderItemMapper.delOrderItemByGoods_id(id);
		TimeLimitedMapper timeLimitedMapper=session.getMapper(TimeLimitedMapper.class);
		timeLimitedMapper.delTimeLimitedByGoods_id(id);
		
		ShopMapper shopMapper=session.getMapper(ShopMapper.class);
		int count=shopMapper.delShopById(id);
		session.commit();
		closeSqlSession();
		return count;
	}
	@Override
	public int delShops(int[] ids) {
		SqlSession session=getSqlSession();
		CommentMapper commentMapper=session.getMapper(CommentMapper.class);
		commentMapper.delCommentsByGoods_id(ids);
		OrderItemMapper orderItemMapper=session.getMapper(OrderItemMapper.class);
		orderItemMapper.delOrderItemsByGoods_id(ids);
		TimeLimitedMapper timeLimitedMapper=session.getMapper(TimeLimitedMapper.class);
		timeLimitedMapper.delTimeLimitedsByGoods_id(ids);
		ShopMapper shopMapper=session.getMapper(ShopMapper.class);
		int count=shopMapper.delShops(ids);
		session.commit();
		closeSqlSession();
		return count;
	}

	@Override
	public int addShop(Shop shop) {
		SqlSession session=getSqlSession();
		ShopMapper shopMapper=session.getMapper(ShopMapper.class);
		int count=shopMapper.addShop(shop);
		session.commit();
		closeSqlSession();
		return count;
	}

	@Override
	public Shop getShopById(int id) {
		SqlSession session=getSqlSession();
		ShopMapper shopMapper=session.getMapper(ShopMapper.class);
		Shop shop=shopMapper.getShopById(id);
		closeSqlSession();
		return shop;
	}

	@Override
	public int shopUpdate(Shop shop) {
		SqlSession session=getSqlSession();
		ShopMapper shopMapper=session.getMapper(ShopMapper.class);
		int count=shopMapper.shopUpdate(shop);
		session.commit();
		closeSqlSession();
		return count;
	}

	@Override
	public List<Shop> getShop() {
		SqlSession session=getSqlSession();
		ShopMapper shopMapper=session.getMapper(ShopMapper.class);
		List<Shop> shops=shopMapper.getShop();
		closeSqlSession();
		return shops;
	}

	@Override
	public List<Shop> getShopByisHot() {
		SqlSession session=getSqlSession();
		ShopMapper shopMapper=session.getMapper(ShopMapper.class);
		List<Shop> shops1=shopMapper.getShopByisHot();
		closeSqlSession();
		return shops1;
	}

	@Override
	public List<Shop> getShopByisHot2() {
		SqlSession session=getSqlSession();
		ShopMapper shopMapper=session.getMapper(ShopMapper.class);
		List<Shop> shops2=shopMapper.getShopByisHot2();
		closeSqlSession();
		return shops2;
	}

	@Override
	public List<Shop> getShopByisHot3() {
		SqlSession session=getSqlSession();
		ShopMapper shopMapper=session.getMapper(ShopMapper.class);
		List<Shop> shops3=shopMapper.getShopByisHot3();
		closeSqlSession();
		return shops3;
	}

	@Override
	public List<Shop> getShopByisHot4() {
		SqlSession session=getSqlSession();
		ShopMapper shopMapper=session.getMapper(ShopMapper.class);
		List<Shop> shops4=shopMapper.getShopByisHot4();
		closeSqlSession();
		return shops4;
	}
	@Override
	public List<Shop> getShopByisHot5() {
		SqlSession session=getSqlSession();
		ShopMapper shopMapper=session.getMapper(ShopMapper.class);
		List<Shop> shops5=shopMapper.getShopByisHot5();
		closeSqlSession();
		return shops5;
	}
	@Override
	public List<Shop> getShopByCode(QueryVo queryVo) {
		SqlSession session=getSqlSession();
		ShopMapper shopMapper=session.getMapper(ShopMapper.class);
		List<Shop> shops=shopMapper.getShopByCode(queryVo);
		closeSqlSession();
		return shops;
	}
	@Override
	public List<Shop> showAllShop() {

		SqlSession session=getSqlSession();
		ShopMapper shopMapper=session.getMapper(ShopMapper.class);
		List<Shop> shops=shopMapper.showAllShop();
		closeSqlSession();
		return shops;
	}

}
